package com.soulmate.product.controller;

import common.pojo.Product;
import common.vo.EasyUIResult;
import common.vo.SysResult;
import com.soulmate.product.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/product/manage")
public class ProductController {
    @Autowired
    private ProductService productService=null;
    /**
     * 分页查询
     */
    @RequestMapping("/pageManage")
    public EasyUIResult queryEasyUIResult(Integer page, Integer rows){
        EasyUIResult easyUIResult=productService.queryEasyUIResult(page,rows);
        return easyUIResult;
    }
    /**
     *  单个商品查询
     */
    @RequestMapping("item/{productId}")
    public Product findProductById(@PathVariable("productId") String productId){
        Product product=productService.findProductById(productId);
        return product;

    }
    /**
     *  商品的新增
     */
    @RequestMapping("/save")
    public SysResult addProduct(Product product){
        try {
            productService.addProduct(product);
            return SysResult.ok();
        } catch (Exception e) {
            e.printStackTrace();
            return SysResult.build(400,"新增失败",null);
        }
    }
    /**
     * 商品的修改
     */
    @RequestMapping("update")
    public SysResult updateProduct(Product product){
        try {
            productService.updateProduct(product);
            return SysResult.ok();
        } catch (Exception e) {
            e.printStackTrace();
            return SysResult.build(400,"更新失败",null);
        }
    }



}
